/*
 * ZENworks Notification Icon
 * Copyright (C) Author: Gangadhar Nagesh Metla (Novell, Inc.)
 * nmetla74@gmail.com 
 * Version 1.0
 * 1/3/2009
 * Filename Animator.java
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

package com.novell.zenworks.agent.zicon;

import com.novell.zenworks.agent.common.ICommonUIEnums.MB_ICON;
import com.novell.zenworks.agent.common.ICommonUIEnums.MB_RESPONSE;
import com.novell.zenworks.agent.common.ICommonUIEnums.MB_TYPE;
import com.novell.zenworks.agent.zbrowser.MessageBoxLauncher;
import com.novell.zenworks.zicon.common.LogUtil;

public class Animator implements Runnable
{
    private Animation a;
    private boolean stop = false;
    private static Object lock = new Object();
    private static Animator instance;
    
    public static Animator getInstance()
    {
        if(instance == null)
        {
            synchronized(lock)
            {
                if(instance == null)
                {
                    instance = new Animator();
                }
            }
        }
        return instance;
    }
    
    private Animator()
    {  
        a = new Animation();
    }
    
    public Animation getAnimation()
    {
        return a;
    }
    
    public boolean isStop()
    {
        return stop;
    }

    public synchronized void setStop(boolean stop)
    {
        this.stop = stop;
    }

    public void run()
    {
        try
        {
            ZTrayIcon.getInstance().getDisplay().timerExec(0, a);
        } catch (Exception e)
        {
            try
            {
                LogUtil.LogException(e.getMessage(), e);

                if(e.getMessage() != null)
                {
                    MessageBoxLauncher.ShowMessageBoxHandler(e.getMessage(), ZTrayIcon.rm.getString("PropDlgTitle") , MB_TYPE.MBT_OK, MB_ICON.MBI_ERROR, 30, false, MB_RESPONSE.MBR_OK);
                }
                else
                {
                    MessageBoxLauncher.ShowMessageBoxHandler(ZTrayIcon.rm.getString("RemotingError"), ZTrayIcon.rm.getString("PropDlgTitle") , MB_TYPE.MBT_OK, MB_ICON.MBI_ERROR, 30, false, MB_RESPONSE.MBR_OK);
                }

            } catch (Exception e1)
            {
                LogUtil.LogException(e.getMessage(), e1);
            }   
        }       
    }
}
